if SUGAR_webber_the_trainer:getModConfigDataFromTUNING('_life') then
    ---@type widget_widget
    local Widget = require 'widgets/widget'
    ---@type widget_image
    local Image = require 'widgets/image'
    ---@type widget_button
    local Button = require "widgets/button"
    ---@type widget_imagebutton
    local ImageButton = require 'widgets/imagebutton'
    ---@type widget_text
    local Text = require 'widgets/text'
    ---@type widget_textedit
    local TextEdit = require "widgets/textedit"
    ---@type widget_uianim
    local UIAnim = require "widgets/uianim"
    local TEMPLATES = require "widgets/redux/templates"

    ---@class widget_webbert_life_btn : widget_widget
    ---@field btn widget_imagebutton
    ---@field text widget_text
    ---@field frame widget_image
    local webbert_life_btn = Class(Widget,
    ---@param self widget_webbert_life_btn
    function(self)
        Widget._ctor(self, 'webbert_life_btn')

        local scale,f_scale = .18,.2
        self.btn = self:AddChild(ImageButton('images/button_icons.xml','profile.tex','profile.tex','profile.tex','profile.tex','profile.tex'))
        self.btn:SetPosition(-150,200)
        self.btn:SetNormalScale(scale,scale,scale)
        self.btn:SetFocusScale(f_scale,f_scale,f_scale)
        self.btn:SetOnGainFocus(function ()
            if not self.frame.shown then
                self.frame:Show()
            end
        end)
        self.btn:SetOnLoseFocus(function ()
            if self.frame.shown then
                self.frame:Hide()
            end
        end)
        self.btn:SetOnClick(function ()
            if ThePlayer and ThePlayer.HUD and ThePlayer.HUD.webbert_life_panel and not ThePlayer.HUD.webbert_life_panel.shown then
                ThePlayer.HUD.webbert_life_panel:Show()
            end
        end)

        self.text = self.btn:AddChild(Text(BODYTEXTFONT, 25, STRINGS.MOD_WEBBER_THE_TRAINER.UI.life.life))

        self.frame = self.btn:AddChild(Image('images/hud.xml','slot_select.tex','slot_select.tex'))
        self.frame:SetScale(.8,.8,.8)
        self.frame:SetClickable(false)
        self.frame:Hide()
    end)

    -- TAB页面添加一个生涯按钮
    AddClassPostConstruct('screens/playerstatusscreen',
    function (self, ...)
        local old_DoInit = self.DoInit
        function self:DoInit(ClientObjs,...)
            local res = old_DoInit ~= nil and old_DoInit(self,ClientObjs,...) or nil
            if self.root then
                if self.webbert_life == nil then
                    ---@type widget_webbert_life_btn # TAB页面添加一个生涯按钮
                    self.webbert_life = self.root:AddChild(webbert_life_btn())
                end
                if ThePlayer and ThePlayer.HUD and ThePlayer.HUD.webbert_life_panel then
                    ThePlayer.HUD.webbert_life_panel:_createPlayerList()
                end
            end
            return res
        end
    end)

    -- 生涯界面
    local webbert_life_panel = require('core_webber_the_trainer/widgets/webbert_life_panel')

    ---@class screen_playerhud_webbert : widget_screen
    ---@field webbert_life_panel widget_webbert_life_panel

    AddClassPostConstruct('screens/playerhud',
    ---comment
    ---@param self screen_playerhud_webbert
    function (self, ...)
        self.webbert_life_panel = self:AddChild(webbert_life_panel())
        self.webbert_life_panel:Hide()
    end)

    -- 当某个playerhud显示时, 禁用玩家控制, 并且可以用esc退出该界面
    local player_hud_field = 'webbert_life_panel'
    AddComponentPostInit('playercontroller',
    ---comment
    ---@param self component_playercontroller
    function(self)
        -- 能不能玩家控制角色
        local old_IsEnabled = self.IsEnabled
        function self:IsEnabled(...)
            if ThePlayer and ThePlayer.HUD and ThePlayer.HUD[player_hud_field] and ThePlayer.HUD[player_hud_field].shown then
                return false
            end
            return old_IsEnabled(self,...)
        end
    end)

    AddClassPostConstruct('screens/playerhud',
    function (self, ...)
        local press_esc = nil
        local old_OnControl = self.OnControl
        function self:OnControl(control, down,...)
            if control == CONTROL_PAUSE then
                if down then
                    if ThePlayer and ThePlayer.HUD and ThePlayer.HUD[player_hud_field] and ThePlayer.HUD[player_hud_field].shown then
                        ThePlayer.HUD[player_hud_field]:Hide()
                        press_esc = true
                    end
                else
                    -- 防止弹起时 打开pause窗口
                    if press_esc then
                        press_esc = nil
                        return
                    end
                end
            end
            return old_OnControl(self,control,down,...)
        end
    end)
end
